#include<bits/stdc++.h>
using namespace std;
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int T;
    cin>>T;
    while(T)
    {
        int n,m,l,v;
        cin>>n>>m>>l>>v;
        int a[n+1],c[n+1],d[m+1];
        int b[n+1];
        for(int i=1;i<=n;i++)
            cin>>a[i]>>b[i]>>c[i];
        for(int i=1;i<=m;i++)
        {
            cin>>d[i];
        }
        int sum=0,k=0,j=0;
        for(int i=1;i<=n;i++)
        {
            if(c[i]==0) sum++;
            else k++;
        }
        if(sum==n)
        {
            for(int i=1;i<=n;i++)
            if(b[i]>v) j++;
            if(j==0) cout<<j<<" "<<m<<endl;
            else cout<<j<<" "<<m-1<<endl;
        }
        else if(k==n)
        {
            for(int i=1;i<=n;i++)
            {
                b[i]=sqrt(b[i]*b[i]+2*c[i]*(l-a[i]));
                if(b[i]>v) j++;
            }
            if(j==0) cout<<j<<" "<<m<<'\n';
            else cout<<j<<" "<<m-1<<'\n';
        }
          T--;
    }

    return 0;
}

